
if SERVER then
 
	AddCSLuaFile ("shared.lua")
 
	SWEP.Weight = 5
	SWEP.AutoSwitchTo = false
	SWEP.AutoSwitchFrom = false
 
elseif CLIENT then 
 

	SWEP.PrintName = "Frag Grenade"
 
	SWEP.Slot = 4
	SWEP.SlotPos = 1
	SWEP.DrawAmmo = false
	SWEP.DrawCrosshair = false
 
	//Ensures a clean looking notification when a chair is undone. How it works:
	//When you create an undo, you specify the ID:
	//		undo.Create("Some_Identity")
	//By creating an associated language, we can make the undo notification look better:
	//		language.Add("Undone_Some_Identity", "Some message...")
 
	language.Add("Undone_Thrown_SWEP_Entity","Undone Thrown SWEP Entity")
end
 
SWEP.Author = "Your Name"
SWEP.Contact = "Your Email Address"
SWEP.Purpose = "What your SWep does."
SWEP.Instructions = "How to operate your SWep"
SWEP.HoldType			= "grenade"
 

SWEP.Category = "Category"
 
SWEP.Spawnable = true
SWEP.AdminSpawnable = true 
 
SWEP.ViewModel 					= "models/weapons/v_eq_fraggrenade.mdl"
SWEP.WorldModel 				= "models/weapons/w_eq_fraggrenade.mdl"
 
 

SWEP.Primary.ClipSize = 1
SWEP.Primary.DefaultClip = 1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
 
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
 

local ShootSound = Sound("Metal.SawbladeStick")
 
function SWEP:Reload()
end
 
function SWEP:Think()
end
 

 
function SWEP:throw_attack (model_file)
	//Get an eye trace. This basically draws an invisible line from
	//the players eye. This SWep makes very little use of the trace, except to 
	//calculate the amount of force to apply to the object thrown.
	local tr = self.Owner:GetEyeTrace()
 
	//Play some noises/effects using the sound we precached earlier
	self:EmitSound(ShootSound)
	self.BaseClass.ShootEffects(self)
 
	//We now exit if this function is not running serverside
	if (!SERVER) then return end
 
	//The next task is to create a physics prop based on the supplied model
	local ent = ents.Create("prop_physics")
	ent:SetModel(model_file)
 
	//Set the initial position and angles of the object. This might need some fine tuning;
	//but it seems to work for the models I have tried.
	ent:SetPos(self.Owner:EyePos() + (self.Owner:GetAimVector() * 16))
	ent:SetAngles(self.Owner:EyeAngles())
	ent:Spawn()
 
	//Now we need to get the physics object for our entity so we can apply a force to it
	local phys = ent:GetPhysicsObject()
 
	//Check if the physics object is valid. If not, remove the entity and stop the function
	if !(phys && IsValid(phys)) then ent:Remove() return end
 
	//Time to apply the force. My method for doing this was almost entirely empirical 
	//and it seems to work fairly intuitively with chairs.
	phys:ApplyForceCenter(self.Owner:GetAimVector():GetNormalized() *  math.pow(tr.HitPos:Length(), .85))

	//Now for the important part of adding the spawned objects to the undo and cleanup lists.
	cleanup.Add(self.Owner, "props", ent)
 
	undo.Create ("Thrown_SWEP_Entity")
	undo.AddEntity (ent)
	undo.SetPlayer (self.Owner)
	undo.Finish()
end
 
 

function SWEP:PrimaryAttack()

	self:throw_attack("models/weapons/w_eq_fraggrenade.mdl")
--	self.Weapon:SendWeaponAnim( ACT_VM_THROW )
--	self.Owner:SetAnimation( PLAYER_ATTACK1 )
--	self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
	self:PinPulled()
end
 
function SWEP:PinPulled()
	
		self.Weapon:SendWeaponAnim(ACT_VM_PULLPIN)
 
 end
 
function SWEP:SecondaryAttack()

end